/**
 * Copyright (c) 2011-2020, hubin (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.agree.util.excel.enums;

/**
 * <p>
 * 表数据查询
 * </p>
 *
 * @author hubin, tangguo
 * @since 2016-04-25
 */
public enum QuerySQL {
    MYSQL("mysql", "show tables", "show table status", "show full fields from `%s`", "NAME", "COMMENT", "FIELD", "TYPE",
            "COMMENT", "KEY", "Null"),

    ORACLE("oracle", "SELECT a.TABLE_NAME,b.comments FROM USER_TABLES a left join USER_TAB_COMMENTS b on a.TABLE_NAME = b.table_name where a.TABLE_NAME = ?"
            , "SELECT * FROM USER_TAB_COMMENTS where table_name = ?",
            "SELECT A.COLUMN_NAME, CASE WHEN A.DATA_TYPE='NUMBER' THEN " +
                    " (CASE WHEN A.DATA_PRECISION IS NULL THEN A.DATA_TYPE " +
                    " WHEN NVL(A.DATA_SCALE, 0) > 0 THEN A.DATA_TYPE||'('||A.DATA_PRECISION||','||A.DATA_SCALE||')' " +
                    " ELSE A.DATA_TYPE||'('||A.DATA_PRECISION||')' END) " +
                    " ELSE A.DATA_TYPE||'('||A.DATA_LENGTH||')' END DATA_TYPE," +
                    " B.COMMENTS,NVL2(C.POSITION, 'PRI','') KEY, " +
                    " CASE WHEN A.NULLABLE = 'Y' THEN 'N' ELSE 'Y' END AS COLMUST " +
                    " FROM USER_TAB_COLUMNS A INNER JOIN USER_COL_COMMENTS B ON A.TABLE_NAME = B.TABLE_NAME" +
                    " AND A.COLUMN_NAME = B.COLUMN_NAME LEFT JOIN USER_CONSTRAINTS D " +
                    " ON D.TABLE_NAME = A.TABLE_NAME AND D.CONSTRAINT_TYPE = 'P' " +
                    " LEFT JOIN USER_CONS_COLUMNS C ON C.CONSTRAINT_NAME = D.CONSTRAINT_NAME " +
                    " AND C.COLUMN_NAME=A.COLUMN_NAME WHERE A.TABLE_NAME = ? ORDER BY A.COLUMN_ID",
            "TABLE_NAME", "COMMENTS", "COLUMN_NAME", "DATA_TYPE", "COMMENTS", "KEY", "COLMUST"),
    ;

    private final String dbType;
    private final String tablesSql;
    private final String tableCommentsSql;
    private final String tableFieldsSql;
    private final String tableName;
    private final String tableComment;
    private final String fieldName;
    private final String fieldType;
    private final String fieldComment;
    private final String fieldKey;
    private final String fieldIsNullable;

    QuerySQL(final String dbType, final String tablesSql, final String tableCommentsSql, final String tableFieldsSql,
             final String tableName, final String tableComment, final String fieldName, final String fieldType,
             final String fieldComment, final String fieldKey, final String fieldIsNullable) {
        this.dbType = dbType;
        this.tablesSql = tablesSql;
        this.tableCommentsSql = tableCommentsSql;
        this.tableFieldsSql = tableFieldsSql;
        this.tableName = tableName;
        this.tableComment = tableComment;
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.fieldComment = fieldComment;
        this.fieldKey = fieldKey;
        this.fieldIsNullable = fieldIsNullable;
    }

    public String getDbType() {
        return dbType;
    }

    public String getTablesSql() {
        return tablesSql;
    }

    public String getTableCommentsSql() {
        return tableCommentsSql;
    }

    public String getTableFieldsSql() {
        return tableFieldsSql;
    }

    public String getTableName() {
        return tableName;
    }

    public String getTableComment() {
        return tableComment;
    }

    public String getFieldName() {
        return fieldName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public String getFieldComment() {
        return fieldComment;
    }

    public String getFieldKey() {
        return fieldKey;
    }

    public String getFieldIsNullable() {
        return fieldIsNullable;
    }

}
